﻿package com.winmastergames.lolgame {
	import com.winmastergames.lolgame.gameUtils;

	public class consoleParser {
		public static var cheatsEnabled:Boolean = false;
		public static var lNumber:Number = 1;

		public static function ParseConsoleInput(input:String){
			if (engine.cslin >= 7){
				engine.consoleMC.txtConsole.text = "";
				engine.cslin = 0;
			}
			var strin:String = input.replace("\r", "");
			if (strin.indexOf(":") != -1){
				var arrin:Array = strin.split(":");
				switch (arrin[0]){
					case "echo":
						engine.cslin += 1;
						engine.consoleMC.txtConsole.appendText(arrin[1] + "\r\n");
						break;
					case "give":
						if (cheatsEnabled == true){
							engine.cslin += 1;
							player.currentWeaponArray[player.currentWeapon] = "[" + arrin[1] + "]";
							engine.consoleMC.txtConsole.appendText("Pushed [" + arrin[1] + "] into currentWeaponArray\r\n");
						} else {
							engine.cslin += 1;
							engine.consoleMC.txtConsole.appendText("Cheats not Enabled!\r\n");
						}
						break;
					case "give_money":
						if (cheatsEnabled == true)
							player.money += arrin[1];
						else
							engine.consoleMC.txtConsole.appendText("Cheats Not Enabled\r\n");
						break;
					case "set":
						if (cheatsEnabled == true){
							engine.cslin += 1;
							switch (arrin[1]){
								case "gameState":
									engine.consoleMC.txtConsole.appendText("gameState Set to: " + arrin[2] + "\r\n");
									gameUtils.setState(arrin[2]);
									break;
								case "fireSpeed":
									engine.consoleMC.txtConsole.appendText("fireSpeed Set to: " + arrin[2] + "\r\n");
									engine.fireSpeed = arrin[2];
									break;
								case "currentWeaponArray":
									player.currentWeaponArray.push(arrin[2]);
									engine.consoleMC.txtConsole.appendText("Pushed " + arrin[2] + " into currentWeaponArray\r\n");
									break;
								case "ldig":
									lNumber = arrin[2];
									engine.consoleMC.txtConsole.appendText("ldig = " + arrin[2]);
									break;
							}
						} else {
							engine.cslin += 1;
							engine.consoleMC.txtConsole.appendText("Cheats not Enabled!\r\n");
						}
						break;
					case "get":
						switch (arrin[1]){
						case "stageScaleMode":
							engine.cslin += 1;
							engine.consoleMC.txtConsole.appendText("stageScaleMode = " + engine.st_stage.scaleMode.toString() + "\r\n");
							break;
						case "stageWidth":
							engine.cslin += 1;
							engine.consoleMC.txtConsole.appendText("stageWidth = " + engine.st_stage.stageWidth.toString() + "\r\n");
							break;
						case "stageHeight":
							engine.cslin += 1;
							engine.consoleMC.txtConsole.appendText("stageHeight = " + engine.st_stage.stageHeight.toString() + "\r\n");
							break;
						case "stageWidth2":
							engine.cslin += 1;
							engine.consoleMC.txtConsole.appendText("stageWidth = " + engine.st_stage.width.toString() + "\r\n");
							break;
						case "stageHeight2":
							engine.cslin += 1;
							engine.consoleMC.txtConsole.appendText("stageHeight = " + engine.st_stage.height.toString() + "\r\n");
							break;
						case "gameState":
							engine.cslin += 1;
							engine.consoleMC.txtConsole.appendText("gameState = " + gameUtils.getState() + "\r\n");
							break;
						case "ldig":
							engine.cslin += 1;
							engine.consoleMC.txtConsole.appendText("ldig = " + lNumber + "\r\n");
							break;
						case "fireSpeed":
							engine.cslin += 1;
							engine.consoleMC.txtConsole.appendText("fireSpeed = " + engine.fireSpeed + "\r\n");
							break;
						case "bOnScreen":
							engine.cslin += 1;
							engine.consoleMC.txtConsole.appendText("bOnScreen = " + engine.bOnScreen + "\r\n");
							break;
						case "eRemaining":
							engine.cslin += 1;
							engine.consoleMC.txtConsole.appendText("eRemaining = " + engine.eRemaining + "\r\n");
							break;
						case "list":
							engine.cslin += 4;
							engine.consoleMC.txtConsole.appendText("Variable\r\n");
							engine.consoleMC.txtConsole.appendText("-fireSpeed\r\n");
							engine.consoleMC.txtConsole.appendText("-bOnScreen\r\n");
							engine.consoleMC.txtConsole.appendText("-eRemaining\r\n");
					}
						break;
					default:
						engine.cslin += 1;
						engine.consoleMC.txtConsole.appendText("Error, Invalid Input Type 'help' to learn about console.\r\n");
						break;
				}
			} else {
				switch (strin){
					case "help":
						engine.cslin += 3;
						engine.consoleMC.txtConsole.appendText("Command                               Description\r\n");
						engine.consoleMC.txtConsole.appendText("-lines                                          Gets Displayed Lines in Console\r\n");
						engine.consoleMC.txtConsole.appendText("-echo:[string]                        Echo's Given String\r\n");
						engine.consoleMC.txtConsole.appendText("-set:[variable]:[set to]      Set's Given Variable to Given String\r\n");
						engine.consoleMC.txtConsole.appendText("-get:[variable]                      Get's Given Variable Data\r\n");
						engine.consoleMC.txtConsole.appendText("-wafflez1337 enable cheats\r\n");
						break;
					case "wafflez1337":
						engine.cslin += 1;
						if (cheatsEnabled == false){
							cheatsEnabled = true;
							engine.consoleMC.txtConsole.appendText("Cheats Enabled for this Session.\r\n");
						} else if (cheatsEnabled == true){
							cheatsEnabled = false;
							engine.consoleMC.txtConsole.appendText("Cheats Disabled for this Session.\r\n");
						}
						break;
					case "infammo":
						engine.cslin++;
						if (cheatsEnabled == true){
							if (engine.infAmmo == false){
								engine.infAmmo = true;
								engine.consoleMC.txtConsole.appendText("Infinite Ammo turned on\r\n");
							} else {
								engine.infAmmo = false;
								engine.consoleMC.txtConsole.appendText("Infinite Ammo turned off\r\n");
							}
						} else {
							engine.consoleMC.txtConsole.appendText("Cheats not turned on\r\n");
						}
						break;
					case "lines":
						engine.cslin += 1;
						engine.consoleMC.txtConsole.appendText("Current Console Lines: " + engine.cslin + "\r\n");
						break;
					case "enable_pnd":
						engine.pathnodeDebugMC.visible = true;
						break;
					case "disable_pnd":
						engine.pathnodeDebugMC.visible = false;
						break;
					case "killall":
						if (cheatsEnabled == true){
							if (engine.st_enemyArray.length >= 0){
								var deleted:Number = 0;
								var alreadydeleted:Number = 0;
								for (var i:Number = 0; i < engine.st_enemyArray.length; i++){
									if (engine.st_enemyArray[i] != 1337){
										try {
											engine.st_enemyArray[i].killSelf();
											engine.st_hbArray[i].killSelf();
											deleted++;
										} catch (e:Error){
											alreadydeleted++;
										}
									} else {
										alreadydeleted++;
									}
								}
								engine.cslin += 1;
								engine.consoleMC.txtConsole.appendText("Killed " + deleted + " Enemy/Enemies, " + alreadydeleted + " already Deleted\r\n");
							} else {
								engine.cslin += 1;
								engine.consoleMC.txtConsole.appendText("No Enemies to Kill\r\n");
							}
						} else {
							engine.cslin += 1;
							engine.consoleMC.txtConsole.appendText("Cheats not Enabled!\r\n");
						}
						break;
					case "noclip":
						if (cheatsEnabled == true){
							if (engine.noclip == false){
								engine.noclip = true;
							} else {
								engine.noclip = false;
							}
						} else {
							engine.consoleMC.txtConsole.appendText("Cheats Not Enabled\r\n");
						}
					case "god":
						if (cheatsEnabled == true){
							if (engine.god == false){
								engine.god = true;
							} else {
								engine.god = false;
							}
						} else {
							engine.consoleMC.txtConsole.appendText("Cheats Not Enabled\r\n");
						}
						break;
					case "mp_on":
						engine.mpstate = true;
						break;
					default:
						engine.cslin += 1;
						engine.consoleMC.txtConsole.appendText("Error, Invalid Input Type 'help' to learn about console.\r\n");
						break;
				}
			}
		}
	}
}